<script>
    var page = '<?= site_url(); ?>/<?= $chart ?>';
    var page2 = '<?= site_url(); ?>/home/req_kelurahan/';
    function  req_chart(datax) {
        $.ajax({
            url: page,
            type: "post",
            data: datax,
            beforeSend: function() {
                $('#div_chart').html('<img src="<?=  base_url(); ?>/static/images/loading.gif" alt="Loading data Kependudukan" border="0" style="margin-left:35%; margin-top:10%" width="300px">');
            },
            success: function(response) {
                $('#div_chart').html(response);
            }
        });
    }
    function  req_kelurahan(datax) {
        $.ajax({
            url: page2,
            type: "post",
            data: datax,
            beforeSend: function() {
                // setting a timeout
            },
            success: function(response) {
                $('#chart_pilih_kelurahan').html(response);
            }
        });
    }
    $(document).ready(function() {
        req_chart({});
    });
    $('#chart_pilih_kecamatan').on('change', function() {
        console.log('kecamatan berubah ' + $('#chart_pilih_kecamatan').val());
        req_chart({id_kecamatan: $('#chart_pilih_kecamatan').val()});
        $('#chart_pilih_kelurahan').val(0);
        req_kelurahan({id_kecamatan: $('#chart_pilih_kecamatan').val()});
    });
    $('#chart_pilih_kelurahan').on('change', function() {
        req_chart({id_kecamatan: $('#chart_pilih_kecamatan').val(), id_kelurahan: $('#chart_pilih_kelurahan').val()});
    });
</script>